package com.zzyl.nursing.controller.member;

import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.github.pagehelper.Page;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.PageResult;
import com.zzyl.nursing.vo.ReservationCountVo;
import com.zzyl.nursing.vo.ReservationVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:篍
 * @Date: 2025/08/21 10:17
 * @Description:
 */
@RestController
@RequestMapping("/member/reservation")
public class MemberReservationController {

    @Autowired
    private IFamilyMemberService familyMemberService;

    /**
     * 获取取消的预约数量
     * @return
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("获取取消的预约数量")
    public AjaxResult  getCancelledCount() {
        Long count=familyMemberService.getCancelledCount();
        return AjaxResult.success(count);
    }

    /**
     * 查询每个时间段剩余预约次数
     * @return
     */
    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public AjaxResult  countByTime(Long time) {
        List<ReservationCountVo> list=familyMemberService.countByTime(time);
        return AjaxResult.success(list);
    }

    /**
     * 新增预约
     */
    @PostMapping
    @ApiOperation("新增预约")
    public AjaxResult add(@RequestBody ReservationVo reservationVo) {
        familyMemberService.addReservation(reservationVo);
        return AjaxResult.success();
    }


    /**
     * 分页查询预约
     */
    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    public AjaxResult page(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                              @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                              @RequestParam(value = "status",required = false) Integer status) {
        PageResult<Reservation> pageResult =familyMemberService.page(pageNum, pageSize, status);
        return AjaxResult.success(pageResult);
    }

    /**
     * 取消预约
     */
    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public AjaxResult cancel(@PathVariable Long id) {
        familyMemberService.cancel(id);
        return AjaxResult.success();
    }
}
